/*    */ package com.zimbra.cs.datasource.imap;
/*    */ 
/*    */ import com.zimbra.cs.mailclient.imap.ImapConnection;
/*    */ import com.zimbra.cs.mailclient.imap.ListData;
/*    */ import java.io.IOException;
/*    */ import java.util.ArrayList;
/*    */ import java.util.Collections;
/*    */ import java.util.Comparator;
/*    */ import java.util.List;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public final class ImapUtil
/*    */ {
/*    */   private static final String INBOX = "INBOX";
/* 30 */   private static final int INBOX_LEN = "INBOX".length();
/*    */   
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/* 37 */   private static final Comparator<ListData> COMPARATOR = new Comparator()
/*    */   {
/*    */     public int compare(ListData ld1, ListData ld2) {
/* 40 */       return ld2.getMailbox().compareToIgnoreCase(ld1.getMailbox());
/*    */     }
/*    */   };
/*    */   
/*    */   public static List<ListData> listFolders(ImapConnection ic, String name) throws IOException
/*    */   {
/* 46 */     return sortFolders(ic.list("", name));
/*    */   }
/*    */   
/*    */   public static List<ListData> sortFolders(List<ListData> folders)
/*    */   {
/* 51 */     ListData inbox = null;
/* 52 */     ListData defaultInbox = null;
/* 53 */     List<ListData> inboxInferiors = new ArrayList();
/* 54 */     List<ListData> otherFolders = new ArrayList();
/* 55 */     for (ListData ld : folders) {
/* 56 */       if ("INBOX".equalsIgnoreCase(ld.getMailbox())) {
/* 57 */         if (inbox == null)
/*    */         {
/* 59 */           inbox = ld;
/*    */         }
/* 61 */       } else if (isInboxInferior(ld)) {
/* 62 */         inboxInferiors.add(ld);
/* 63 */         if (defaultInbox == null) {
/* 64 */           defaultInbox = new ListData("INBOX", ld.getDelimiter());
/*    */         }
/*    */       } else {
/* 67 */         otherFolders.add(ld);
/*    */       }
/*    */     }
/* 70 */     List<ListData> sorted = new ArrayList(folders.size());
/* 71 */     if (inbox == null)
/*    */     {
/*    */ 
/* 74 */       inbox = defaultInbox;
/*    */     }
/* 76 */     if (inbox != null) {
/* 77 */       sorted.add(inbox);
/*    */     }
/* 79 */     Collections.sort(inboxInferiors, COMPARATOR);
/* 80 */     sorted.addAll(inboxInferiors);
/* 81 */     Collections.sort(otherFolders, COMPARATOR);
/* 82 */     sorted.addAll(otherFolders);
/* 83 */     return sorted;
/*    */   }
/*    */   
/*    */ 
/*    */ 
/*    */ 
/*    */   private static boolean isInboxInferior(ListData ld)
/*    */   {
/* 91 */     String name = ld.getMailbox();
/* 92 */     return (name.length() > INBOX_LEN) && ("INBOX".equalsIgnoreCase(name.substring(0, INBOX_LEN))) && (name.charAt(INBOX_LEN) == ld.getDelimiter());
/*    */   }
/*    */   
/*    */ 
/*    */   public static boolean isYahoo(ImapConnection ic)
/*    */   {
/* 98 */     return ic.hasCapability("AUTH=XYMCOOKIEB64");
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/datasource/imap/ImapUtil.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */